#region File Description
//-----------------------------------------------------------------------------
// PauseMenuScreen.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion

#region Using Statements
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using FolderData;
#endregion


namespace Folder
{
    /// <summary>
    /// The pause menu comes up over the top of the game,
    /// giving the player options to resume or quit.
    /// </summary>
    class PauseMenuScreen : MenuScreen
    {
        #region Fields

        Texture2D tex_bg, tex_selected;

        GameplayScreen _screen;

        #endregion

        #region Initialization


        /// <summary>
        /// Constructor.
        /// </summary>
        public PauseMenuScreen(GameplayScreen screen)
        {
            // Flag that there is no need for the game to transition
            // off when the pause menu is on top of it.
            IsPopup = true;
            _screen = screen;

            // Create our menu entries.
            for (int i = 0; i < 4; ++i)
            {
                MenuEntry entry = new MenuEntry("");
                entry.Position = new Vector2(760, 250 + 70 * i);
                entry.isActive = true;
                entry.Font = Fonts.ContentFont;
                MenuEntries.Add(entry);
            }

            MenuEntries[0].Text = "Continue";
            MenuEntries[0].Selected += new EventHandler<EventArgs>(continue_Selected);
            MenuEntries[1].Text = "Restart";
            MenuEntries[1].Selected += new EventHandler<EventArgs>(restart_Selected);
            MenuEntries[2].Text = "To Contents";
            MenuEntries[2].Selected += new EventHandler<EventArgs>(tocontents_Selected);
            MenuEntries[3].Text = "Exit";
            MenuEntries[3].Selected += new EventHandler<EventArgs>(exit_Selected);
        }

        public override void LoadContent()
        {
            ContentManager content = ScreenManager.Game.Content;

            tex_bg = content.Load<Texture2D>("Menu/Stage/esc_bg");
            tex_selected = content.Load<Texture2D>("Menu/content_selected_small");

            base.LoadContent();
        }

        #endregion

        #region Handle Input

        void continue_Selected(object sender, EventArgs e)
        {
            ExitScreen();
        }
        void restart_Selected(object sender, EventArgs e)
        {
            ExitScreen();
            _screen.ExitScreen();

            ScreenManager.AddScreen(new GameplayScreen(_screen.MapAssetName, _screen.MapNumber));
        }
        void tocontents_Selected(object sender, EventArgs e)
        {
            ScreenManager.RemoveScreen(this);
            ScreenManager.RemoveScreen(_screen);

            ScreenManager.AddScreen(new ContentsScreen(_screen.MapNumber));
        }
        void exit_Selected(object sender, EventArgs e)
        {
            Environment.Exit(0);
        }



        #endregion

        #region Draw

        Rectangle active = new Rectangle(0, 0, 250, 50);
        Rectangle selected = new Rectangle(0, 50, 250, 50);
        Rectangle inactive = new Rectangle(0, 100, 250, 50);
        Rectangle menuSize = new Rectangle(0, 0, 250, 50);

        Vector2 pos_bg = new Vector2(750, 100);

        /// <summary>
        /// Draws the pause menu screen. This darkens down the gameplay screen
        /// that is underneath us, and then chains to the base MenuScreen.Draw.
        /// </summary>
        public override void Draw(GameTime gameTime)
        {
            SpriteBatch spriteBatch = ScreenManager.SpriteBatch;

            spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.SaveState);
            spriteBatch.Draw(tex_bg, pos_bg, TransitionColor);

            for (int i = 0; i < MenuEntries.Count; i++)
            {
                MenuEntry menuEntry = MenuEntries[i];

                bool isSelected = IsActive && (i == selectedEntry);
                if (isSelected)
                {
                    menuEntry.Draw(this, InverseTransitionColor);
                    spriteBatch.Draw(tex_selected, menuEntry.Position - new Vector2(0, -30), TransitionColor);
                }
                else if (menuEntry.isActive)
                {
                    menuEntry.Draw(this, InverseTransitionColor);
                }
                else
                {
                    menuEntry.Draw(this, InverseTransitionColorDisabled);
                }
            }
            /*
            // Draw each menu entry in turn.
            for (int i = 0; i < MenuEntries.Count; i++)
            {
                MenuEntry menuEntry = MenuEntries[i];

                bool isSelected = IsActive && (i == selectedEntry);
                if (isSelected)
                {
                    menuEntry.Draw(this, selected, TransitionColor);
                }
                else if (menuEntry.isActive)
                {
                    menuEntry.Draw(this, active, TransitionColor);
                }
                else
                {
                    menuEntry.Draw(this, inactive, TransitionColor);
                }
            }*/

            spriteBatch.End();

            base.Draw(gameTime);
        }


        #endregion
    }
}
